﻿using Benlai.Common;
using Benlai.Model.Product;
using Benlai.SOA.Framework.Client;
using Benlai.SOA.Framework.Common;
using Benlai.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Benlai.Bll.Product
{
    public class ProductClient
    {
        private ProductClient() { }
        private static object lockobj = new object();
        private static ProductClient _instance;
        public static ProductClient GetInstance()
        {
            if (_instance != null)
            {
                return _instance;
            }

            lock (lockobj)
            {
                if (_instance != null)
                {
                    return _instance;
                }

                if (_instance == null)
                {
                    _instance = new ProductClient();
                }
                return _instance;
            }
        }
        
        private static readonly string IPAddress = ConfigUtil.GetAppSetting("ProductServiceIPAddress");
        
        /// <summary>
        /// 获取仓库审核的商品信息
        /// </summary>
        /// <param name="productSysNo">商品编号</param>
        /// <returns></returns>
        public ResponseInfo<StoreAduitProductModel> GetStoreAduitInfo(int productSysNo)
        {
            using (var client = new BenlaiTcpClient(IPAddress))
            {
                Dictionary<string, object> dicQuery = new Dictionary<string, object> { { "productSysNo", productSysNo } };
                string result = client.GetResponse("/Product/GetStoreAduitInfo", dicQuery);
                ResponseInfo<StoreAduitProductModel> response = JsonSerializerUnits.DeserializeObject<ResponseInfo<StoreAduitProductModel>>(result);
                return response;
            }
        }

        /// <summary>
        /// 仓库审核 商品信息
        /// </summary>
        /// <param name="model">仓库审核的商品信息</param>
        /// <returns></returns>
        public ResponseInfo<bool> AduitProductByStore(StoreAduitProductModel model)
        {
            using (var client = new BenlaiTcpClient(IPAddress))
            {
                Dictionary<string, object> dicQuery = new Dictionary<string, object> { { "model", model } };
                string result = client.GetResponse("/Product/AduitProductByStore", dicQuery);
                ResponseInfo<bool> response = JsonSerializerUnits.DeserializeObject<ResponseInfo<bool>>(result);
                return response;
            }
        }

    }
}
